home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Game / board / Saga.lha / Saga / source / counters.c < prev    next >
C/C++ Source or Header  |  2004-09-01  |  24KB  |  654 lines

  1. // 1. INCLUDES -----------------------------------------------------------
  2.  
  3. #include <exec/types.h>
  4. #include <exec/alerts.h>
  5. #include <intuition/intuition.h>
  6. #include <graphics/gfx.h>
  7. #include <graphics/displayinfo.h>
  8. #include <graphics/gels.h>
  9. #include <graphics/view.h>
  10.  
  11. #include <stdlib.h>
  12.  
  13. #include "animtools.h"
  14. #include "saga.h"
  15. #include "counters.h"
  16.  
  17. // 2. DEFINES ------------------------------------------------------------
  18.  
  19. // 3. EXPORTED VARIABLES -------------------------------------------------
  20.  
  21. EXPORT NEWBOB NewBob =
  22. {   NULL,               // initial image
  23.     COUNTERWIDTH,       // width in words
  24.     COUNTERHEIGHT,      // line height
  25.     2,                  // image depth
  26.     1,                  // PlanePick
  27.     0x7F,               // PlaneOnOff
  28.     SAVEBACK | OVERLAY, // VSprite flags
  29.     FALSE,              // double buffer?
  30.     0,                  // raster depth
  31.     HIDDEN_X, HIDDEN_Y, // x, y position (filled later)
  32.     0,                  // hit mask
  33.     0                   // me mask
  34. };
  35.  
  36. // 4. IMPORTED VARIABLES -------------------------------------------------
  37.  
  38. IMPORT struct Custom         custom;
  39.  
  40. IMPORT struct GfxBase*       GfxBase;
  41. IMPORT struct Window        *MainWindowPtr,
  42.                             *InfoWindowPtr;
  43. IMPORT struct WorldStruct    world[36 + 30];
  44. IMPORT struct HeroStruct     hero[HEROES + 1];
  45. IMPORT struct JarlStruct     jarl[JARLS + 1];
  46. IMPORT struct MonsterStruct  monster[MONSTERS + 1];
  47. IMPORT struct TreasureStruct treasure[TREASURES + 1];
  48. IMPORT struct SordStruct     sord[SORDS + 1];
  49. IMPORT UWORD                 DisplayDepth;
  50. IMPORT SLONG                 treasures;
  51.  
  52. // 5. MODULE VARIABLES ---------------------------------------------------
  53.  
  54. MODULE struct GelsInfo*      GInfoPtr = NULL;
  55. MODULE struct Bob           *HeroBobPtr[HEROES + 1],
  56.                             *JarlBobPtr[JARLS + 1],
  57.                             *MonsterBobPtr[MONSTERS + 1],
  58.                             *TreasureBobPtr[TREASURES + 1],
  59.                             *SordBobPtr[SORDS + 1];
  60.  
  61. /* The word `Sword' is deliberately mispelled (within the source code) as
  62.    Sord. This avoids any confusion with the SWORD (signed word) typedef. */
  63.  
  64. // 6. MODULE STRUCTURES --------------------------------------------------
  65.  
  66. // 7. MODULE FUNCTIONS ---------------------------------------------------
  67.  
  68. MODULE void shadowcounter(SWORD x, SWORD y);
  69.  
  70. // 8. CODE ---------------------------------------------------------------
  71.  
  72. AGLOBAL void createcounters(void)
  73. {   SLONG whichhero, whichjarl, whichmonster, whichtreasure, whichsord;
  74.  
  75.     if (!(GInfoPtr = setupGelSys(MainWindowPtr->RPort, 0x03)))
  76.     {   DisplayAlert(AT_Recovery, "\0\20\20Saga: Can't set up GELs!\0", 24);
  77.         cleanexit(EXIT_FAILURE);
  78.     }
  79.     NewBob.nb_RasDepth = DisplayDepth;
  80.  
  81.     NewBob.nb_PlaneOnOff = 114;
  82.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  83.     {   NewBob.nb_Image = (WORD *) HeroData[whichhero];
  84.         if (!(HeroBobPtr[whichhero] = makeBob(&NewBob)))
  85.         {   DisplayAlert(AT_Recovery, "\0\20\20Saga: Can't make hero bob(s)!\0", 24);
  86.             cleanexit(EXIT_FAILURE);
  87.         }
  88.         AddBob(HeroBobPtr[whichhero], MainWindowPtr->RPort);
  89.     }
  90.  
  91.     // We seem to lose memory in this routine; not sure why...
  92.  
  93.     NewBob.nb_PlaneOnOff = 116;
  94.     for (whichjarl = 0; whichjarl <= JARLS; whichjarl++)
  95.     {   NewBob.nb_Image = (WORD *) UnknownJarlData;
  96.         if (!(JarlBobPtr[whichjarl] = makeBob(&NewBob)))
  97.         {   DisplayAlert(AT_Recovery, "\0\20\20Saga: Can't make jarl bob(s)!\0", 24);
  98.             cleanexit(EXIT_FAILURE);
  99.         }
  100.         AddBob(JarlBobPtr[whichjarl], MainWindowPtr->RPort);
  101.     }
  102.     NewBob.nb_PlaneOnOff = 118;
  103.     for (whichmonster = 0; whichmonster <= MONSTERS; whichmonster++)
  104.     {   NewBob.nb_Image = (WORD *) MonsterData[whichmonster];
  105.         if (!(MonsterBobPtr[whichmonster] = makeBob(&NewBob)))
  106.         {   DisplayAlert(AT_Recovery, "\0\20\20Saga: Can't make monster bob(s)!\0", 24);
  107.             cleanexit(EXIT_FAILURE);
  108.         }
  109.         AddBob(MonsterBobPtr[whichmonster], MainWindowPtr->RPort);
  110.     }
  111.  
  112.     NewBob.nb_PlaneOnOff = 120;
  113.     for (whichsord = 0; whichsord <= SORDS; whichsord++)
  114.     {   NewBob.nb_Image = (WORD *) SordData[whichsord];
  115.         if (!(SordBobPtr[whichsord] = makeBob(&NewBob)))
  116.         {   DisplayAlert(AT_Recovery, "\0\20\20Saga: Can't make sword bob(s)!\0", 24);
  117.             cleanexit(EXIT_FAILURE);
  118.         }
  119.         AddBob(SordBobPtr[whichsord], MainWindowPtr->RPort);
  120.     }
  121.  
  122.     NewBob.nb_PlaneOnOff = 122;
  123.     for (whichtreasure = 0; whichtreasure <= TREASURES; whichtreasure++)
  124.     {   NewBob.nb_Image = (WORD *) TreasureData[whichtreasure];
  125.         if (!(TreasureBobPtr[whichtreasure] = makeBob(&NewBob)))
  126.         {   DisplayAlert(AT_Recovery, "\0\20\20Saga: Can't make treasure bob(s)!\0", 24);
  127.             cleanexit(EXIT_FAILURE);
  128.         }
  129.         AddBob(TreasureBobPtr[whichtreasure], MainWindowPtr->RPort);
  130.     }
  131. }
  132.  
  133. AGLOBAL void destroycounters(void)
  134. {   SLONG whichhero,
  135.           whichjarl,
  136.           whichmonster,
  137.           whichtreasure,
  138.           whichsord;
  139.  
  140.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  141.     {   if (HeroBobPtr[whichhero])
  142.         {   remove_hero(whichhero, FALSE);
  143.             RemBob(HeroBobPtr[whichhero]);
  144.     }   }
  145.     for (whichjarl = 0; whichjarl <= JARLS; whichjarl++)
  146.     {   if (JarlBobPtr[whichjarl])
  147.         {   remove_jarl(whichjarl, FALSE);
  148.             RemBob(JarlBobPtr[whichjarl]);
  149.     }   }
  150.     for (whichmonster = 0; whichmonster <= MONSTERS; whichmonster++)
  151.     {   if (MonsterBobPtr[whichmonster])
  152.         {   remove_monster(whichmonster, FALSE);
  153.             RemBob(MonsterBobPtr[whichmonster]);
  154.     }   }
  155.     for (whichtreasure = 0; whichtreasure <= TREASURES; whichtreasure++)
  156.     {   if (TreasureBobPtr[whichtreasure])
  157.         {   remove_treasure(whichtreasure, FALSE);
  158.             RemBob(TreasureBobPtr[whichtreasure]);
  159.     }   }
  160.     for (whichsord = 0; whichsord <= SORDS; whichsord++)
  161.     {   if (SordBobPtr[whichsord])
  162.         {   remove_sord(whichsord, FALSE);
  163.             RemBob(SordBobPtr[whichsord]);
  164.     }   }
  165.  
  166.     /* if (GInfoPtr)
  167.     {   refreshcounters();
  168.     } */
  169.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  170.     {   if (HeroBobPtr[whichhero])
  171.         {   freeBob(HeroBobPtr[whichhero], NewBob.nb_RasDepth);
  172.             HeroBobPtr[whichhero] = NULL;
  173.     }   }
  174.     for (whichjarl = 0; whichjarl <= JARLS; whichjarl++)
  175.     {   if (JarlBobPtr[whichjarl])
  176.         {   freeBob(JarlBobPtr[whichjarl], NewBob.nb_RasDepth);
  177.             JarlBobPtr[whichjarl] = NULL;
  178.     }   }
  179.     for (whichmonster = 0; whichmonster <= MONSTERS; whichmonster++)
  180.     {   if (MonsterBobPtr[whichmonster])
  181.         {   freeBob(MonsterBobPtr[whichmonster], NewBob.nb_RasDepth);
  182.             MonsterBobPtr[whichmonster] = NULL;
  183.     }   }
  184.     for (whichtreasure = 0; whichtreasure <= TREASURES; whichtreasure++)
  185.     {   if (TreasureBobPtr[whichtreasure])
  186.         {   freeBob(TreasureBobPtr[whichtreasure], NewBob.nb_RasDepth);
  187.             TreasureBobPtr[whichtreasure] = NULL;
  188.     }   }
  189.     for (whichsord = 0; whichsord <= SORDS; whichsord++)
  190.     {   if (SordBobPtr[whichsord])
  191.         {   freeBob(SordBobPtr[whichsord], NewBob.nb_RasDepth);
  192.             SordBobPtr[whichsord] = NULL;
  193.     }   }
  194.  
  195.     if (GInfoPtr)
  196.     {   cleanupGelSys(GInfoPtr, MainWindowPtr->RPort);
  197. }   }
  198.  
  199. AGLOBAL void unslot_hero(SLONG whichhero)
  200. {   if (hero[whichhero].slot != -1)
  201.     {   world[hero[whichhero].where].slot[hero[whichhero].slot] = FALSE;
  202.         hero[whichhero].slot = -1;
  203. }   }
  204. AGLOBAL void unslot_jarl(SLONG whichjarl)
  205. {   if (jarl[whichjarl].slot != -1)
  206.     {   world[jarl[whichjarl].where].slot[jarl[whichjarl].slot] = FALSE;
  207.         jarl[whichjarl].slot = -1;
  208. }   }
  209. AGLOBAL void unslot_monster(SLONG whichmonster)
  210. {   if (monster[whichmonster].slot != -1)
  211.     {   world[monster[whichmonster].where].slot[monster[whichmonster].slot] = FALSE;
  212.         monster[whichmonster].slot = -1;
  213. }   }
  214. AGLOBAL void unslot_treasure(SLONG whichtreasure)
  215. {   if (treasure[whichtreasure].slot != -1)
  216.     {   world[treasure[whichtreasure].where].slot[treasure[whichtreasure].slot] = FALSE;
  217.         treasure[whichtreasure].slot = -1;
  218. }   }
  219. AGLOBAL void unslot_sord(SLONG whichsord)
  220. {   if (sord[whichsord].slot != -1)
  221.     {   world[sord[whichsord].where].slot[sord[whichsord].slot] = FALSE;
  222.         sord[whichsord].slot = -1;
  223. }   }
  224.  
  225. AGLOBAL void move_hero(SLONG whichhero, FLAG display)
  226. {   SLONG whichslot;
  227.  
  228.     // This assumes the counter has already been unslotted from its old
  229.     // location.
  230.     for (whichslot = 0; whichslot <= SLOTS; whichslot++)
  231.     {   if (!(world[hero[whichhero].where].slot[whichslot]))
  232.         {   hero[whichhero].slot = whichslot;
  233.             break;
  234.     }   }
  235.     world[hero[whichhero].where].slot[whichslot] = TRUE;
  236.  
  237.     HeroBobPtr[whichhero]->BobVSprite->X = world[hero[whichhero].where].centrex - 12;
  238.     HeroBobPtr[whichhero]->BobVSprite->Y = world[hero[whichhero].where].centrey - 12 - (whichslot * 7);
  239.     if (display)
  240.     {   refreshcounters();
  241. }   }
  242. AGLOBAL void move_monster(SLONG whichmonster, FLAG display)
  243. {   SLONG whichslot;
  244.  
  245.     // This assumes the counter has already been unslotted from its old
  246.     // location.
  247.     for (whichslot = 0; whichslot <= SLOTS; whichslot++)
  248.     {   if (!(world[monster[whichmonster].where].slot[whichslot]))
  249.         {   monster[whichmonster].slot = whichslot;
  250.             break;
  251.     }   }
  252.     world[monster[whichmonster].where].slot[whichslot] = TRUE;
  253.  
  254.     MonsterBobPtr[whichmonster]->BobVSprite->X = world[monster[whichmonster].where].centrex - 12;
  255.     MonsterBobPtr[whichmonster]->BobVSprite->Y = world[monster[whichmonster].where].centrey - 12 - (whichslot * 7);
  256.     if (display)
  257.     {   refreshcounters();
  258. }   }
  259. AGLOBAL void move_jarl(SLONG whichjarl, FLAG display)
  260. {   SLONG whichslot;
  261.  
  262.     // This assumes the counter has already been unslotted from its old
  263.     // location.
  264.     for (whichslot = 0; whichslot <= SLOTS; whichslot++)
  265.     {   if (!(world[jarl[whichjarl].where].slot[whichslot]))
  266.         {   jarl[whichjarl].slot = whichslot;
  267.             break;
  268.     }   }
  269.     world[jarl[whichjarl].where].slot[whichslot] = TRUE;
  270.  
  271.     JarlBobPtr[whichjarl]->BobVSprite->X = world[jarl[whichjarl].where].centrex - 12;
  272.     JarlBobPtr[whichjarl]->BobVSprite->Y = world[jarl[whichjarl].where].centrey - 12 - (whichslot * 7);
  273.     if (display)
  274.     {   refreshcounters();
  275. }   }
  276. AGLOBAL void move_treasure(SLONG whichtreasure, FLAG display)
  277. {   SLONG whichslot;
  278.  
  279.     // This assumes the counter has already been unslotted from its old
  280.     // location.
  281.     for (whichslot = 0; whichslot <= SLOTS; whichslot++)
  282.     {   if (!(world[treasure[whichtreasure].where].slot[whichslot]))
  283.         {   treasure[whichtreasure].slot = whichslot;
  284.             break;
  285.     }   }
  286.     world[treasure[whichtreasure].where].slot[whichslot] = TRUE;
  287.  
  288.     TreasureBobPtr[whichtreasure]->BobVSprite->X = world[treasure[whichtreasure].where].centrex - 12;
  289.     TreasureBobPtr[whichtreasure]->BobVSprite->Y = world[treasure[whichtreasure].where].centrey - 12 - (whichslot * 7);
  290.     if (display)
  291.     {   refreshcounters();
  292. }   }
  293. AGLOBAL void move_sord(SLONG whichsord, FLAG display)
  294. {   SLONG whichslot;
  295.  
  296.     // This assumes the counter has already been unslotted from its old
  297.     // location.
  298.     for (whichslot = 0; whichslot <= SLOTS; whichslot++)
  299.     {   if (!(world[sord[whichsord].where].slot[whichslot]))
  300.         {   sord[whichsord].slot = whichslot;
  301.             break;
  302.     }   }
  303.     world[sord[whichsord].where].slot[whichslot] = TRUE;
  304.  
  305.     SordBobPtr[whichsord]->BobVSprite->X = world[sord[whichsord].where].centrex - 12;
  306.     SordBobPtr[whichsord]->BobVSprite->Y = world[sord[whichsord].where].centrey - 12 - (whichslot * 7);
  307.     if (display)
  308.     {   refreshcounters();
  309. }   }
  310.  
  311. AGLOBAL void init_counters(void)
  312. {   SLONG whichhero, whichjarl, whichmonster, whichtreasure, whichsord;
  313.  
  314.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  315.     {   hero[whichhero].slot = -1;
  316.         HeroBobPtr[whichhero] = NULL;
  317.     }
  318.     for (whichjarl = 0; whichjarl <= JARLS; whichjarl++)
  319.     {   jarl[whichjarl].slot = -1;
  320.         JarlBobPtr[whichjarl] = NULL;
  321.     }
  322.     for (whichmonster = 0; whichmonster <= MONSTERS; whichmonster++)
  323.     {   monster[whichmonster].slot = -1;
  324.         MonsterBobPtr[whichmonster] = NULL;
  325.     }
  326.     for (whichtreasure = 0; whichtreasure <= TREASURES; whichtreasure++)
  327.     {   treasure[whichtreasure].slot = -1;
  328.         TreasureBobPtr[whichtreasure] = NULL;
  329.     }
  330.     for (whichsord = 0; whichsord <= SORDS; whichsord++)
  331.     {   sord[whichsord].slot = -1;
  332.         SordBobPtr[whichsord] = NULL;
  333. }   }
  334.  
  335. AGLOBAL void revealjarl(SLONG whichjarl, FLAG display)
  336. {   jarl[whichjarl].face        = FACEUP;
  337.     jarl[whichjarl].recruitable = TRUE;
  338.     JarlBobPtr[whichjarl]->BobVSprite->ImageData = (WORD *) JarlData[whichjarl];
  339.     // InitMasks(JarlBobPtr[whichjarl]->BobVSprite);
  340.     if (display)
  341.     {   refreshcounters();
  342. }   }
  343.  
  344. AGLOBAL void hidejarl(SLONG whichjarl, FLAG display)
  345. {   jarl[whichjarl].face        = FACEDOWN;
  346.     jarl[whichjarl].recruitable = FALSE;
  347.     JarlBobPtr[whichjarl]->BobVSprite->ImageData = (WORD *) UnknownJarlData;
  348.     // InitMasks(JarlBobPtr[whichjarl]->BobVSprite);
  349.     if (display)
  350.     {   refreshcounters();
  351. }   }
  352.  
  353. AGLOBAL SLONG checkcounters(SWORD mousex, SWORD mousey, SLONG* countertype)
  354. {   SLONG foundy,
  355.           whichhero,
  356.           whichcounter = -1,
  357.           whichjarl,
  358.           whichmonster,
  359.           whichtreasure, whichsord;
  360.     FLAG  found = FALSE;
  361.  
  362.     *(countertype) = -1;
  363.  
  364.     /* This assumes that counters with higher y-values (ie. lower on the
  365.     screen) have higher priority than those with lower y-values. */
  366.  
  367.     // find all counters lying under the pointer
  368.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  369.     {   if
  370.         (   mousex >= HeroBobPtr[whichhero]->BobVSprite->X
  371.          && mousex <= HeroBobPtr[whichhero]->BobVSprite->X + 24 - 1
  372.          && mousey >= HeroBobPtr[whichhero]->BobVSprite->Y
  373.          && mousey <= HeroBobPtr[whichhero]->BobVSprite->Y + 24 - 1
  374.         )
  375.         {   hero[whichhero].foundbob = TRUE;
  376.             found = TRUE;
  377.     }   }
  378.     for (whichjarl = 0; whichjarl <= JARLS; whichjarl++)
  379.     {   if
  380.         (   mousex >= JarlBobPtr[whichjarl]->BobVSprite->X
  381.          && mousex <= JarlBobPtr[whichjarl]->BobVSprite->X + 24 - 1
  382.          && mousey >= JarlBobPtr[whichjarl]->BobVSprite->Y
  383.          && mousey <= JarlBobPtr[whichjarl]->BobVSprite->Y + 24 - 1
  384.         )
  385.         {   jarl[whichjarl].foundbob = TRUE;
  386.             found = TRUE;
  387.     }   }
  388.     for (whichmonster = 0; whichmonster <= MONSTERS; whichmonster++)
  389.     {   if
  390.         (   mousex >= MonsterBobPtr[whichmonster]->BobVSprite->X
  391.          && mousex <= MonsterBobPtr[whichmonster]->BobVSprite->X + 24 - 1
  392.          && mousey >= MonsterBobPtr[whichmonster]->BobVSprite->Y
  393.          && mousey <= MonsterBobPtr[whichmonster]->BobVSprite->Y + 24 - 1
  394.         )
  395.         {   monster[whichmonster].foundbob = TRUE;
  396.             found = TRUE;
  397.     }   }
  398.     for (whichtreasure = 0; whichtreasure <= TREASURES; whichtreasure++)
  399.     {   if
  400.         (   mousex >= TreasureBobPtr[whichtreasure]->BobVSprite->X
  401.          && mousex <= TreasureBobPtr[whichtreasure]->BobVSprite->X + 24 - 1
  402.          && mousey >= TreasureBobPtr[whichtreasure]->BobVSprite->Y
  403.          && mousey <= TreasureBobPtr[whichtreasure]->BobVSprite->Y + 24 - 1
  404.         )
  405.         {   treasure[whichtreasure].foundbob = TRUE;
  406.             found = TRUE;
  407.     }   }
  408.     for (whichsord = 0; whichsord <= SORDS; whichsord++)
  409.     {   if
  410.         (   mousex >= SordBobPtr[whichsord]->BobVSprite->X
  411.          && mousex <= SordBobPtr[whichsord]->BobVSprite->X + 24 - 1
  412.          && mousey >= SordBobPtr[whichsord]->BobVSprite->Y
  413.          && mousey <= SordBobPtr[whichsord]->BobVSprite->Y + 24 - 1
  414.         )
  415.         {   sord[whichsord].foundbob = TRUE;
  416.             found = TRUE;
  417.     }   }
  418.  
  419.     if (!found)
  420.     {   return(-1);
  421.     }
  422.  
  423.     // determine which counter is topmost (ie. which is lower on the screen)
  424.     foundy = -1;
  425.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  426.     {   if
  427.         (   hero[whichhero].foundbob
  428.          && HeroBobPtr[whichhero]->BobVSprite->Y > foundy
  429.         )
  430.         {   whichcounter = whichhero;
  431.             *(countertype) = HERO;
  432.             foundy = HeroBobPtr[whichhero]->BobVSprite->Y;
  433.         }
  434.         hero[whichhero].foundbob = FALSE;
  435.     }
  436.     for (whichjarl = 0; whichjarl <= JARLS; whichjarl++)
  437.     {   if
  438.         (   jarl[whichjarl].foundbob
  439.          && JarlBobPtr[whichjarl]->BobVSprite->Y > foundy
  440.         )
  441.         {   whichcounter = whichjarl;
  442.             *(countertype) = JARL;
  443.             foundy = JarlBobPtr[whichjarl]->BobVSprite->Y;
  444.         }
  445.         jarl[whichjarl].foundbob = FALSE;
  446.     }
  447.     for (whichmonster = 0; whichmonster <= MONSTERS; whichmonster++)
  448.     {   if
  449.         (   monster[whichmonster].foundbob
  450.          && MonsterBobPtr[whichmonster]->BobVSprite->Y > foundy
  451.         )
  452.         {   whichcounter = whichmonster;
  453.             *(countertype) = MONSTER;
  454.             foundy = MonsterBobPtr[whichmonster]->BobVSprite->Y;
  455.         }
  456.         monster[whichmonster].foundbob = FALSE;
  457.     }
  458.     for (whichtreasure = 0; whichtreasure <= TREASURES; whichtreasure++)
  459.     {   if
  460.         (   treasure[whichtreasure].foundbob
  461.          && TreasureBobPtr[whichtreasure]->BobVSprite->Y > foundy
  462.         )
  463.         {   whichcounter = whichtreasure;
  464.             *(countertype) = TREASURE;
  465.             foundy = TreasureBobPtr[whichtreasure]->BobVSprite->Y;
  466.         }
  467.         treasure[whichtreasure].foundbob = FALSE;
  468.     }
  469.     for (whichsord = 0; whichsord <= SORDS; whichsord++)
  470.     {   if
  471.         (   sord[whichsord].foundbob
  472.          && SordBobPtr[whichsord]->BobVSprite->Y > foundy
  473.         )
  474.         {   whichcounter = whichsord;
  475.             *(countertype) = SORD;
  476.             foundy = SordBobPtr[whichsord]->BobVSprite->Y;
  477.         }
  478.         sord[whichsord].foundbob = FALSE;
  479.     }
  480.  
  481.     return(whichcounter);
  482. }
  483.  
  484. AGLOBAL void select_hero(SLONG whichhero, FLAG display)
  485. {   if (hero[whichhero].promoted != -1)
  486.     {   HeroBobPtr[whichhero]->BobVSprite->ImageData = (WORD *) JarlData[hero[whichhero].promoted];
  487.     } else
  488.     {   HeroBobPtr[whichhero]->BobVSprite->ImageData = (WORD *) HeroData[whichhero];
  489.     }
  490.     HeroBobPtr[whichhero]->BobVSprite->PlaneOnOff = 124;
  491.     // InitMasks(HeroBobPtr[whichhero]->BobVSprite);
  492.     if (display)
  493.     {   refreshcounters();
  494. }   }
  495. AGLOBAL void deselect_hero(SLONG whichhero, FLAG display)
  496. {   if (hero[whichhero].promoted != -1)
  497.     {   HeroBobPtr[whichhero]->BobVSprite->ImageData = (WORD *) JarlData[hero[whichhero].promoted];
  498.     } else
  499.     {   HeroBobPtr[whichhero]->BobVSprite->ImageData = (WORD *) HeroData[whichhero];
  500.     }
  501.     HeroBobPtr[whichhero]->BobVSprite->PlaneOnOff = 114;
  502.     // InitMasks(HeroBobPtr[whichhero]->BobVSprite);
  503.     if (display)
  504.     {   refreshcounters();
  505. }   }
  506. AGLOBAL void select_jarl(SLONG whichjarl, FLAG display)
  507. {   JarlBobPtr[whichjarl]->BobVSprite->PlaneOnOff = 124;
  508.     // InitMasks(JarlBobPtr[whichjarl]->BobVSprite);
  509.     if (display)
  510.     {   refreshcounters();
  511. }   }
  512. AGLOBAL void deselect_jarl(SLONG whichjarl, FLAG display)
  513. {   JarlBobPtr[whichjarl]->BobVSprite->PlaneOnOff = 116;
  514.     // InitMasks(JarlBobPtr[whichjarl]->BobVSprite);
  515.     if (display)
  516.     {   refreshcounters();
  517. }   }
  518. AGLOBAL void select_monster(SLONG whichmonster, FLAG display)
  519. {   MonsterBobPtr[whichmonster]->BobVSprite->PlaneOnOff = 124;
  520.     // InitMasks(MonsterBobPtr[whichmonster]->BobVSprite);
  521.     if (display)
  522.     {   refreshcounters();
  523. }   }
  524. AGLOBAL void deselect_monster(SLONG whichmonster, FLAG display)
  525. {   MonsterBobPtr[whichmonster]->BobVSprite->PlaneOnOff = 118;
  526.     // InitMasks(JarlBobPtr[whichjarl]->BobVSprite);
  527.     if (display)
  528.     {   refreshcounters();
  529. }   }
  530.  
  531. AGLOBAL void remove_hero(SLONG whichhero, FLAG display)
  532. {   unslot_hero(whichhero);
  533.     HeroBobPtr[whichhero]->BobVSprite->X = HIDDEN_X;
  534.     HeroBobPtr[whichhero]->BobVSprite->Y = HIDDEN_Y;
  535.     if (display)
  536.     {   refreshcounters();
  537. }   }
  538. AGLOBAL void remove_jarl(SLONG whichjarl, FLAG display)
  539. {   unslot_jarl(whichjarl);
  540.     JarlBobPtr[whichjarl]->BobVSprite->X = HIDDEN_X;
  541.     JarlBobPtr[whichjarl]->BobVSprite->Y = HIDDEN_Y;
  542.     if (display)
  543.     {   refreshcounters();
  544. }   }
  545. AGLOBAL void remove_monster(SLONG whichmonster, FLAG display)
  546. {   unslot_monster(whichmonster);
  547.     MonsterBobPtr[whichmonster]->BobVSprite->X = HIDDEN_X;
  548.     MonsterBobPtr[whichmonster]->BobVSprite->Y = HIDDEN_Y;
  549.     if (display)
  550.     {   refreshcounters();
  551. }   }
  552. AGLOBAL void remove_treasure(SLONG whichtreasure, FLAG display)
  553. {   unslot_treasure(whichtreasure);
  554.     TreasureBobPtr[whichtreasure]->BobVSprite->X = HIDDEN_X;
  555.     TreasureBobPtr[whichtreasure]->BobVSprite->Y = HIDDEN_Y;
  556.     if (display)
  557.     {   refreshcounters();
  558. }   }
  559. AGLOBAL void remove_sord(SLONG whichsord, FLAG display)
  560. {   unslot_sord(whichsord);
  561.     SordBobPtr[whichsord]->BobVSprite->X = HIDDEN_X;
  562.     SordBobPtr[whichsord]->BobVSprite->Y = HIDDEN_Y;
  563.     if (display)
  564.     {   refreshcounters();
  565. }   }
  566.  
  567. AGLOBAL void refreshcounters(void)
  568. {   /* Unfortunately, it would seem that the DrawGList() call turns the
  569.     display back on automatically */
  570.  
  571.     screenoff();
  572.     SortGList(MainWindowPtr->RPort);
  573.     DrawGList(MainWindowPtr->RPort, ViewPortAddress(MainWindowPtr));
  574.     screenon();
  575. }
  576.  
  577. AGLOBAL void reset_images(void)
  578. {   SLONG whichhero;
  579.  
  580.     for (whichhero = 0; whichhero <= HEROES; whichhero++)
  581.     {   HeroBobPtr[whichhero]->BobVSprite->ImageData = (WORD *) HeroData[whichhero];
  582.         // InitMasks(HeroBobPtr[whichhero]->BobVSprite);
  583. }   }
  584.  
  585. AGLOBAL void info(SLONG countertype, SLONG counter)
  586. {   SLONG infobobs = 0,
  587.           which;
  588.  
  589.     // If we have a jarl with five or six treasures, the fifth and sixth
  590.     // treasure counters will not fit into the window.
  591.  
  592.     for (which = 0; which <= TREASURES; which++)
  593.     {   if
  594.         (   treasure[which].possessortype == countertype
  595.          && treasure[which].possessor     == counter
  596.         )
  597.         {   Counter.ImageData  = TreasureData[which];
  598.             Counter.PlaneOnOff = 122;
  599.             shadowcounter(596, 7 + (infobobs * (24 + 4)));
  600.             infobobs++;
  601.     }   }
  602.  
  603.     infobobs = 0;
  604.     for (which = 0; which <= SORDS; which++)
  605.     {   if
  606.         (   sord[which].possessortype == countertype
  607.          && sord[which].possessor     == counter
  608.         )
  609.         {   Counter.ImageData  = SordData[which];
  610.             Counter.PlaneOnOff = 120;
  611.  
  612.             shadowcounter(568, 7);
  613.             infobobs = 1;
  614.             break;
  615.     }   }
  616.     if (countertype == HERO)
  617.     {   for (which = 0; which <= JARLS; which++)
  618.         {   if
  619.             (   jarl[which].alive
  620.              && jarl[which].hero == counter
  621.             )
  622.             {   Counter.ImageData  = JarlData[which];
  623.                 Counter.PlaneOnOff = 116;
  624.                 shadowcounter(568, 7 + (infobobs * (24 + 4)));
  625.                 infobobs++;
  626. }   }   }   }
  627.  
  628. MODULE void shadowcounter(SWORD x, SWORD y)
  629. {   DrawImage(InfoWindowPtr->RPort, &Counter, x, y);
  630.  
  631.      SetAPen(InfoWindowPtr->RPort, BLACK);
  632.     Move(InfoWindowPtr->RPort, x + 1 + 24, y + 1     );
  633.     Draw(InfoWindowPtr->RPort, x + 1 + 24, y + 1 + 24);
  634.     Draw(InfoWindowPtr->RPort, x + 1     , y + 1 + 24);
  635. }
  636.  
  637. AGLOBAL void doc(SLONG number)
  638. {   SLONG which;
  639.  
  640.     SetAPen(InfoWindowPtr->RPort, BLACK);
  641.     if (number == 3) // swords
  642.     {   Counter.PlaneOnOff = 120;
  643.         for (which = 0; which <= SORDS; which++)
  644.         {   Counter.ImageData  = SordData[which];
  645.             shadowcounter(12, sord[which].y);
  646.         }
  647.     } elif (number == 4) // treasures
  648.     {   Counter.PlaneOnOff = 122;
  649.         for (which = 0; which <= treasures; which++)
  650.         {   Counter.ImageData  = TreasureData[which];
  651.             shadowcounter(12, treasure[which].y);
  652. }   }   }
  653.  
  654.